package com.wu.orderadd.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.wu.beans.Oreders;
import com.wu.orderadd.service.OrederService;
import com.wu.vo.Reultvo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author cxj
 */
@RestController
@RequestMapping("/order")
public class OrederController {

    @Autowired
    private OrederService orederService;
//        @HystrixCommand(fallbackMethod = "fallbackSaveOrder",commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000")
//        ,    @HystrixProperty(name="circuitBreaker.enabled",value="true"),//启⽤服务熔断
//                @HystrixProperty(name="circuitBreaker.sleepWindowInMilliseconds",value="10000"),//时间
//                 @HystrixProperty(name="circuitBreaker.requestVolumeThreshold",value="10"),//请求次数
//                  @HystrixProperty(name="circuitBreaker.errorThresholdPercentage",value="50")//服务错误率
//    })
   // @RequestMapping("/add")
    @PostMapping("/add")
    public Reultvo addOreder(@RequestBody Oreders oreders) {
        return orederService.save(oreders);
    }

     //基于Feign多个参数传递
//    @PostMapping("/add")
//    public Reultvo addOreder(@RequestBody Oreders oreders,String str) {
//        System.out.println("str======================="+str);
//        return orederService.save(oreders);
//    }

//          //使用get请求
//         @GetMapping("/add")
//         public Reultvo addOreder(Oreders oreders) {
//             return orederService.save(oreders);
//        }


    //基于Feign get 请求
    @GetMapping("/get")
    public Oreders addOrder(String orderId){
        System.out.println("从Feingn 客户端穿过的orderId========="+orderId);
        return new Oreders();
    }

    public Reultvo fallbackSaveOrder(@RequestBody Oreders order){
        System.out.println("-------------------order-add--fallback");
        return Reultvo.fail(201,"订单保存失败！");
    }

}
